//use_btn_type函数用来返回另一个计算按钮样式的函数computed_btn_type
import {toRefs} from "vue";
import {verifiable} from "@/components/Picker/composables/config";

export default function use_btn_type(props) {
    const {subjects, mode} = toRefs(props)
    const computed_btn_type = (idx_in_list, type_name) => {
        const {user_answer, answer, checked} = subjects.value[idx_in_list]
        let btn_type = '' //默认为空样式
        //有答案时primary
        if (user_answer) {
            btn_type = 'primary'
        }
        //是否是客观题，verifiable中出现的题型
        if (verifiable.includes(type_name)) {
            //训练模式且用户checked
            const is_train_checked = mode.value === 'train' && checked
            const is_analysis = mode.value === 'analysis'
            const is_right = user_answer === answer//分析答案是否正确
            //当组件模式为训练模式且checked，或者是解析模式时分析答案对错
            if ((is_train_checked || is_analysis) && is_right) {
                btn_type = 'success'
            } else if ((is_train_checked || is_analysis) && !is_right) {
                if(user_answer){
                    btn_type = 'danger'
                }else{
                    btn_type = ''
                }
            }
        }
        return btn_type

    }
    return {computed_btn_type}

}
